package com.fenghongzhang.day006;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;

public class Main3Activity extends AppCompatActivity {
    private Button btn;
    private ImageView img;
    private static final String TAG = "Main3Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);


        btn = (Button) findViewById(R.id.btn);
        img = (ImageView) findViewById(R.id.img);

    }

    public void btn1(View view) {

        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 1000,500);
        valueAnimator.setDuration(3000);
        //基础上+1 = 2
//        valueAnimator.setRepeatCount(1);
//        valueAnimator.setRepeatMode(ValueAnimator.RESTART);
        //监听方法, 每一次值改变.都会调用
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btn.getLayoutParams();
                int animatedValue = (int) animation.getAnimatedValue();
                Log.i(TAG, "onAnimationUpdate: "+animatedValue);
                layoutParams.width = animatedValue;
                layoutParams.height = animatedValue;
                layoutParams.leftMargin = animatedValue;

                btn.setLayoutParams(layoutParams);


            }
        });
        //开始
        valueAnimator.start();

//        Intent intent = new Intent(this, Main2Activity.class);
//        startActivity(intent);
//        overridePendingTransition(R.anim.rotate,R.anim.rotate);

    }

    public void btn2(View view) {
//        AnimatorSet animatorSet = new AnimatorSet();
//        animatorSet.setDuration(3000);
//        animatorSet.setInterpolator(new LinearInterpolator());
//        ObjectAnimator translationX = ObjectAnimator.ofFloat(btn, "translationX", 0, 300);
//        ObjectAnimator rotation = ObjectAnimator.ofFloat(btn, "rotation", 0, 720);
//        ObjectAnimator scaleX = ObjectAnimator.ofFloat(btn, "scaleX", 1, 5);
//        ObjectAnimator scaleY = ObjectAnimator.ofFloat(btn, "scaleY", 1, 5);
//        ObjectAnimator alpha = ObjectAnimator.ofFloat(btn, "alpha", 1, 0);

        //顺序播放
//        animatorSet.playSequentially(translationX, rotation, scaleX, scaleY, alpha);
//        animatorSet.playTogether(scaleX, scaleY);

//        animatorSet.play(translationX).before(rotation);
//        animatorSet.start();


//        ObjectAnimator animator = ObjectAnimator.ofFloat(btn, "rotation",0,360);
//        animator.setDuration(2000);
//        animator.setRepeatCount(1);
//        animator.setInterpolator(new LinearInterpolator());

//        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//
//            }
//        });
//        animator.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animation) {
//                Log.i(TAG, "onAnimationStart: ");
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animation) {
//                Log.i(TAG, "onAnimationEnd: ");
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animation) {
//                Log.i(TAG, "onAnimationCancel: ");
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animation) {
//                Log.i(TAG, "onAnimationRepeat: ");
//            }
//        });
//
//        animator.start();

        Intent intent = new Intent(this, Main2Activity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.rotate,R.anim.alpha);

    }
}
